package com.cj.sys.dao.security;

import org.springframework.stereotype.Repository;

import com.cj.common.orm.hibernate.HibernateDao;
import com.cj.sys.entity.security.Authority;
import com.cj.sys.entity.security.User;

@Repository
public class AuthorityDao extends HibernateDao<Authority, Long> {
	/**
	 * 重载delte，在删除角色时删除与用户关联的中间表.
	 */
	@Override
	public void delete(Long id) {
		Authority authority = this.get(id);
		for (User user : authority.getUsers()) {
			user.getAuthorities().remove(authority);
		}
		super.delete(authority);			
	}
}
